<?php
/**
 * Created by PhpStorm.
 * User: bxm
 * Date: 2022/6/28
 * Time: 0:47
 */

namespace app\api\controller\worker;

use app\api\controller\Base;
use app\common\model\worker\HomeDecorDataModel;
use think\Request;

class HomeDecorDataController extends Base
{
    private $model;
    /**
     * 构造方法
     * @access public
     * @throws \Exception
     */
    public function __construct()
    {

        parent::__construct();
        $this->checkLogin();
        $this->model = new HomeDecorDataModel();

    }
    public function list(){
        $data = $this->request->param();
        $customer_id  = $data['customer_id'];
        $pageSize      = $this->request->param('pageSize/d', 20); //每页多少条
        $pageNumber    = $this->request->param('pageNumber/d') ?? 1; //当前页

        $list = $this->model->alias('cal')->leftJoin('admin a', 'a.id = cal.action_admin_id')
            ->where('customer_id',$customer_id)
            ->field('a.nickname,cal.create_time,cal.customer_id')
            ->order('cal.id','desc') ->paginate(['list_rows'=> $pageSize, 'page' => $pageNumber]);



        $this->result($list,'操作成功',1);
    }
    public function getInfo(Request $request){
        $param = $request->param();
        //开始校验
        $this->validate($param,[
            'id|记录id'=>'require',
        ]);
        $id = $param['id'];
        $list = $this->model->alias('cal')->leftJoin('admin a', 'a.id = cal.action_admin_id')
            ->where('cal.id',$id)
            ->field('a.nickname,cal.*')
           ->find();
        $this->result($list,'操作成功',1);
    }
    public function add(){

        $param = $this->request->param();
        $rule = [
            'customer_file|上传效果图'=>'require',
            'customer_imgs|上传CAD图纸'=>'require',
            'customer_id|客户id'=>'require',
        ];
        $this->validate($param,$rule);
        $data = [
            'customer_id'=>$param['customer_id'],
            'customer_file' => json_encode($param['customer_file'],JSON_UNESCAPED_UNICODE),
            'customer_imgs' => json_encode($param['customer_imgs'],JSON_UNESCAPED_UNICODE),
            'action_admin_id' =>$this->loginInfo['id'],
        ];
        $info = $this->model->add($data);
        $this->result($info,'操作成功',1);
    }

}